package flextv.search.logic {

import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
import flash.utils.setTimeout;

import flextv.core.logic.Logger;
import flextv.core.logic.Util;
import flextv.search.vo.SearchItem;

import mx.collections.ArrayCollection;
import mx.logging.ILogger;
import mx.rpc.IResponder;

public class MockSearchService extends EventDispatcher implements ISearchService {
	
	private static const LOG: ILogger = Logger.getLog(MockSearchService);
	
	private static var currentId: uint = 0;
	
	private static const YID_CHARS: Array = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".split("");
	
	public function MockSearchService(target: IEventDispatcher=null) {
		super(target);
	}
	
	public function search(term: String, responder: IResponder): void {
		LOG.debug("search(term="+term+")");
		
		setTimeout(function(): void {
			
			const searchResult: ArrayCollection = new ArrayCollection();
			const n: uint = Util.randInt(2, 6); // 2-5 result items
			for(var i: uint = 0; i < n; i++) {
				const yid: String = String(Util.randElements(YID_CHARS, 15));
				const thumbnailUrl: String = "";
				searchResult.addItem(new SearchItem(yid, "Dummy Search Item " + (i+1) + "/#" + (++currentId), 3, thumbnailUrl));
			}
			responder.result(searchResult);
			
		}, 200); // sleep
		
	}
	
}
}